$ () ->
	$(".reply_this_btn").click (e) ->
		$("#message_id").val($(e.target).parent().children("#this_message_id").val())
		$("#reply_div").show()
		$("#reply_content").focus().select()
	
	$("#reply_btn").click (e) ->
		param =
			message_id:$("#message_id").val()
			reply_content: $("#reply_content").val()

		$.post "/api/message/create-user-reply", param, (res) ->
			if res.status.errCode is 0
				window.location.reload()
			else
				alert res.status.message


	$("#message_btn").click (e) ->
		param =
			wechat_doctor_info_id: $("#doctor_id").val()
			content: $("#content").val()

		$.post "/api/message/create-message", param, (res) ->
			if res.status.errCode is 0
				window.location.reload()
			else
				alert res.status.message

	$("body").click (e) ->
		if !$(e.target).is('.reply_btn') && !$(e.target).is('#reply_div') && !$(e.target).is('#reply_content') && !$(e.target).is('#reply_btn')
			$("#reply_div").hide()
